//
// Created by wyh on 2024/4/19.
//
#include "stl/vector.h"
#include <sys/time.h>
//#include <vector>
#include <iostream>

using namespace std;
using namespace wyh::stl;

int main(int argc, char **argv) {
    Vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);

    v.show();

    v.pop_back();
    v.show();

    int a = v.front();
    int b = v.back();
    cout << a << "," << b << endl;

    cout<<"1---------------------"<<endl;
    Vector<int> v2 = v;
    v2.show();

    v.resize(10,25);
    v.show();
    v2.show();

    cout<<"2---------------------"<<endl;

    for(auto it = v.begin();it!=v.end();it++)
    {
        std::cout<<*it<<",";
    }
    cout<<endl;

    for(auto it = v.begin();it!=v.end();++it)
    {
        std::cout<<*it<<",";
    }
    cout<<endl;

    for(auto &e:v)
    {
        std::cout<<e<<",";
    }
    cout<<endl;

    cout<<"3---------------------"<<endl;

    for(auto it = v.rbegin();it!=v.rend();it++)
    {
        std::cout<<*it<<",";
    }
    cout<<endl;

    for(auto it = v.rbegin();it!=v.rend();++it)
    {
        std::cout<<*it<<",";
    }
    cout<<endl;

    v.insert(v.begin(),4);
    v.show();

    v.insert(v.begin()+4,3,100);
    v.show();

    cout<<"4---------------------"<<endl;
    v.erase(v.end()-1);
    v.show();

    v.erase(v.begin(),v.begin()+3);
    v.show();

    struct timeval tv;
    gettimeofday(&tv, nullptr);
    int start_sec = tv.tv_sec;
    int start_usec = tv.tv_usec;

    const int max = 1000000;
    Vector<int> v1;
    for(int i = 0;i<max;i++){
        v1.push_back(i);
//            v.insert(v.begin(),i);
    }

    gettimeofday(&tv, nullptr);
    int end_sec = tv.tv_sec;
    int end_usec = tv.tv_usec;

    double time_diff = (end_sec - start_sec)*1000000+(end_usec-start_usec);
    std::cout<<time_diff/1000/max<<"ms"<<std::endl;

    return 0;
}